/**
 * Your MyQueue object will be instantiated and called as such:
 * var obj = new MyQueue()
 * obj.push(x)
 * var param_2 = obj.pop()
 * var param_3 = obj.peek()
 * var param_4 = obj.empty()
 */
class MyQueue {
    private stack1: number[] = []
    private stack2: number[] = []

    constructor() {

    }
    // 加入
    push(x: number): void {
        this.stack1.push(x)
    }
    //  从队列的开头移除并返回元素
    pop(): number|undefined {
        let res;
        // 将 stack 移动到 stack2
        while (this.stack1.length){
            const n = this.stack1.pop()
            if (n!== undefined)this.stack2.push(n)
        }
        res = this.stack2.pop()
        while (this.stack2.length){
            const n = this.stack2.pop()
            if (n!== undefined)this.stack1.push(n)
        }
        return  res || undefined
    }
    // 队列第一个
    peek(): number | undefined {
        if (this.stack1.length > 0) {
            return this.stack1[0]
        }
    }
    // 清空
    empty(): boolean {
        return this.stack1.length === 0
    }
}
